package zhu.areas.user.action;

import java.util.Date;

import org.apache.struts2.ServletActionContext;

import zhu.areas.dic.data.FieldType;
import zhu.areas.dic.data.Role;
import zhu.areas.user.data.Expert;
import zhu.areas.user.data.User;
import zhu.areas.user.service.IExpertService;
import zhu.areas.user.service.IUserService;
import zhu.common.service.IDicService;

import com.opensymphony.xwork2.ActionSupport;

public class ExpertAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private IExpertService expertService;
	private IUserService userService;
	private IDicService dicService;
	
	private Expert expert=new Expert();
	private User user=new User();
	private Role expType;
	private FieldType expField;
	
	private int exp_Type;
	private int exp_Field;
	
	public String changeToAppExpert(){
		return SUCCESS;
	}
	

	public String appExpert(){
		System.out.println("here1");

		user=userService.findByUsername((String) ServletActionContext.getRequest().getSession().getAttribute("userName"));
		expert.setUser(user);
		//expert.setExpName((String) ServletActionContext.getRequest().getSession().getAttribute("userName"));
		expType=(Role) dicService.getValueById("Role","roleID", getExp_Type());
		//System.out.println(expType.getcName());
		expert.setExpType(expType);
		expField=(FieldType)dicService.getValueById("FieldType","fieldTypID", getExp_Field());
		expert.setExpField(expField);
		//expert.setDegree("教授");
		expert.setAppTime(new Date());
		expert.setState(0);
		System.out.println("here2");
		if(expertService.addExpert(expert)){
			System.out.println("保存基本信息成功");
			return SUCCESS;
		}
		else{
			return ERROR;
		}
	}
	
	
	
	
	
	
	public IExpertService getExpertService() {
		return expertService;
	}
	public void setExpertService(IExpertService expertService) {
		this.expertService = expertService;
	}
	public IUserService getUserService() {
		return userService;
	}
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	public IDicService getDicService() {
		return dicService;
	}
	public void setDicService(IDicService dicService) {
		this.dicService = dicService;
	}
	public Expert getExpert() {
		return expert;
	}
	public void setExpert(Expert expert) {
		this.expert = expert;
	}
	public int getExp_Type() {
		return exp_Type;
	}
	public void setExp_Type(int exp_Type) {
		this.exp_Type = exp_Type;
	}
	public int getExp_Field() {
		return exp_Field;
	}
	public void setExp_Field(int exp_Field) {
		this.exp_Field = exp_Field;
	}
	
	
	
	

}
